;(function () {
    var index = {
        init: function () {
            this.lazyBind();
            this.swiperBind();
            this.bindVideoChange();
            this.bindLocalCaseChange();
            this.bindTabsClick();
            // 滚动监听
            $(document).scroll(function (e) {
                if ($(document).scrollTop() > 500) {
                    $('.scroll-top').removeClass('hide');
                } else {
                    $('.scroll-top').addClass('hide');
                }
            });
            // 点击回到顶部
            $('.scroll-top').click(function () {
                $("html,body").animate({"scrollTop": 0})
            });
            // 定时改变多少人已获取装修报价
            this.offerTiming(10000);
            // 点击底部免费报价关闭按钮
            $('.free-program-close').click(function () {
                $(".free-program").addClass('hide');
            });
        },
        load: function () {

        },
        offerTiming: function (times) {
            var _this = this;
            var num = Math.round(Math.random()*30);
            setTimeout(function () {
                $('small .color-orange').html(parseInt($('small .color-orange').html())+num);
                _this.offerTiming(10000);
            }, times);
        },
        lazyBind: function () {
            $("img.lazy").lazyload({
                effect : "fadeIn"
            });
            $("div.lazy").lazyload({
                effect : "fadeIn"
            });
        },
        swiperBind: function () {
            var swiper1 = new Swiper('#swiper-top .swiper-container', {
                autoplay: {
                    delay: 3000,//1秒切换一次
                },
                pagination: {
                    el: '#swiper-top .swiper-pagination',
                    clickable :true,
                },
                navigation: {
                    nextEl: '#swiper-top .swiper-button-next',
                    prevEl: '#swiper-top .swiper-button-prev',
                },
                slidesPerView: 1,
                paginationClickable: true,				lazy: {
                    loadPrevNext: true,
                },
            });
            var swiper2 = new Swiper('#system .swiper-container', {
                autoplay: {
                    delay: 3000,//1秒切换一次
                },
                navigation: {
                    nextEl: '#system  .swiper-button-next',
                    prevEl: '#system  .swiper-button-prev',
                },
                slidesPerView: 1,				lazy: {
                    loadPrevNext: true,
                },
                on: {
                    slideChangeTransitionEnd: function(){
                        $('.system-product-type li').eq(this.activeIndex).addClass('active')
                        .siblings().removeClass('active');
                    },
                },
            });
            var swiper3 = new Swiper('.designer-recommendation-body .swiper-container', {
                autoplay: {
                    delay: 3000,//1秒切换一次
                },
                pagination: {
                    el: '.designer-recommendation-body .swiper-pagination',
                    clickable :true,
                },
                slidesPerView: 1,				lazy: {
                    loadPrevNext: true,
                }
            });
            var swiper4 = new Swiper('#plan .swiper-container', {
                autoplay: {
                    delay: 3000,//1秒切换一次
                },
                navigation: {
                    nextEl: '.plan-body .swiper-button-next',
                    prevEl: '.plan-body .swiper-button-prev',
                },
                slidesPerView: 1,				lazy: {
                    loadPrevNext: true,
                },
                on: {
                    slideChangeTransitionEnd: function(){
                        $('.plan-type li').eq(this.activeIndex).addClass('active')
                        .siblings().removeClass('active');
                    },
                },
            });
            
            $('.serverProcess-product-type li').eq(0).addClass('active');
            $('.plan-type li').eq(0).addClass('active');
            
            this.bindSwiperHover(swiper1, '#swiper-top .swiper-slide');
            this.bindSwiperHover(swiper2, '#system .swiper-slide');
            this.bindSwiperHover(swiper4, '#plan .swiper-slide');
            
            // 绑定轮播中的产品类型选择
            this.bindProductTypeClick(swiper2, '.system-product-type li');
            
            // 绑定轮播中的方案设计类型选择
            this.bindProductTypeClick(swiper4, '.plan-body li');
        },
        // 鼠标移入移除事件，可以暂停轮播
        bindSwiperHover: function (swiper, el) {
        	$(el).mouseenter(function () {
        	    swiper.autoplay.stop();
        	}).mouseleave(function () {
        	    swiper.autoplay.start();
        	})
        },
        bindProductTypeClick: function (swiper, el) {
            $(el).on('click', function () {
                var index = $(this).index();
                swiper.slideTo(index, 1000, false);
                $(el).eq(index).addClass('active')
                .siblings().removeClass('active');
            });
        },
        bindVideoChange: function () {
        	$('.scene-list .bg-img').on('click', function(){
                var url = this.dataset.url;
                var parent = $(this).parents('li');
                parent.addClass('active').siblings().removeClass('active');
        		alert('播放：' + url);
        	});
        },
        bindLocalCaseChange: function () {
            $('.case-local .case-head li').on('click', function () {
                var index = $(this).index();
                var type = this.dataset.type;
                $(this).addClass('active').siblings().removeClass('active');
                alert(type);
            });
        },
        bindTabsClick: function () {
            $('#tabs .tabs-nav li').on('click', function () {
                var index = $(this).index();
                $('#tabs .tabs-nav li').eq(index).addClass('active').siblings().removeClass('active');
                $('#tabs .tabs-content .tabs-pane').eq(index).addClass('active').siblings().removeClass('active');
            });
        }
    };
    index.init();
})();
